/*
 * 
 * LegendShop 多用户商城系统
 * 
 *  版权所有,并保留所有权利。
 * 
 */
package com.legendshop.oa.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.legendshop.dao.support.PageSupport;
import com.legendshop.framework.controller.BaseController;
import com.legendshop.oa.constants.PathResolver;
import com.legendshop.oa.dto.EventQueryDto;
import com.legendshop.oa.model.AdminUser;
import com.legendshop.oa.model.UserEvent;
import com.legendshop.oa.pages.AdminTilesPage;
import com.legendshop.oa.security.UserDetail;
import com.legendshop.oa.security.UserManager;
import com.legendshop.oa.service.EventService;
import com.legendshop.oa.util.PageSupportHelper;
import com.legendshop.permission.service.AdminUserService;
import com.legendshop.util.AppUtils;

/**
 * 我的地盘
 */
@Controller
@RequestMapping("/admin/myland")
public class MyLandController extends BaseController {
	
	/** The log. */
	private final static Logger log = LoggerFactory.getLogger(MyLandController.class);

	@Autowired
	private EventService eventService;
	
	@Autowired
	private AdminUserService adminUserService;

	/**
	 * 项目下的列表查询
	 */
	@RequestMapping("/query")
	public String queryProjectTask(HttpServletRequest request, HttpServletResponse response, EventQueryDto eventQueryDto) {
		log.debug("myland calling");
		UserDetail userDetail = UserManager.getUser(request);
		if(AppUtils.isNotBlank(eventQueryDto.getUserName())){
			eventQueryDto.setUserName(eventQueryDto.getUserName());
		}else{
			eventQueryDto.setUserName(userDetail.getUsername());
		}
		
		eventQueryDto.setPageSize(30);
		PageSupport<UserEvent> ps = eventService.getEventPage(eventQueryDto);
		PageSupportHelper.savePage(request, ps);
		request.setAttribute("eventQueryDto", eventQueryDto);
		
		if(AppUtils.isNotBlank(eventQueryDto.getUserName())){
			AdminUser adminUser = adminUserService.getAdminUserByUserName(eventQueryDto.getUserName());
			if(adminUser != null){
				request.setAttribute("userRealName", adminUser.getRealName());
			}
		}

		return PathResolver.getPath(request, response, AdminTilesPage.MYLAND_PAGE);
	}
	
	

}
